package com.syqc.comlib

import com.syqc.comlib.entity.AppGpsColumn
import com.syqc.comlib.entity.MapMarker
import com.syqc.comlib.utils.AppContext
import com.syqc.comlib.utils.BuildConfigs
import com.syqc.comlib.utils.CacheMMKV


object UserConstant {
    //终端类型版本
    const val PLATFORM_TMN = 20240829


    //当前IP
    var current_ip = ""

    //当前端口
    var current_port = ""

    //用户ID，账户
    var current_userId = ""

    //当前加密后的密码
    var current_pwd = ""

    //当前加密后的密码
    var current_pwd_md5 = ""

    //车辆ID
    var current_carId: String? = ""

    //视频通道
    var current_videos: String? = ""

    //公司ID
    var current_cmpId = ""

    //用户下车辆总数
    var current_car_num = 0

    //会话ID
    var sessionId = ""

    //是否有实时视频权限
    var isRealVideo = false

    //是否有历史视频权限
    var isTapeVideo = false

    //是否有数据界面权限
    var isHomeData = false

    //是否Https
    var isHttps = false

    //是否纯定位模式
    var isLocationMode = false

    //视频服务器地址
    var videohost = ""
    var videohosts: String? = ""

    //登录类型
    var loginType: String = "user"

    var platformVersion = PLATFORM_TMN

    //是否有收费管理权限
    var isFeeManager = false

    //是否是温度统计数据平台
    var isTempPlat = false

    var serviceTime = ""

    //链接ID
    var clientId = ""

    //广告链接
    var adLink_1 = ""
    var adLink_2 = ""
    var adLink_3 = ""
    override fun toString(): String {
        return "super.toString()= isRealVideo= $isRealVideo,isTapeVideo=$isTapeVideo "
    }

}

object AppConfigs {
    //是否需要验证码登录
    var isLoginSms = false

    //是否需要车牌颜色登录
    var isPlateColorVfy = false

    //是否需要Base64密码
    var isBase64Pwd = false

    //是否可以修改密码
    var isUpPwd = false

    //是否过率报警数为0的报警
    var isAlarmFilter = false

    //是否开启报警推送
    var isAlarms = false

    //是否开启欠费通知
    var isArrears = true

    //首页设置
    var homeSet = "homeSet"

    //地图图标参数设置
    var mapMark: MapMarker? = null

    //快捷设置
    var quickSet: MutableList<String>? = null

    //信息窗设置
    var appGpsColumn: MutableList<AppGpsColumn>? = null

    //刷新时间
    var mapRefresh: Int = 5

    //欠费信息相关是否显示
    var arrearsAuth = true

    //固定地图中心
    var isCenter = false

    //定位弹窗默认展开
    var isMapInfoOpen = true

    //轨迹定位信息弹窗默认展开
    var isLineInfoOpen = true

    //是否报警声音
    var isVoice = true

    //是否开启上下线通知
    var isOnOffLine = false

    //模式
    var model = "0"

    //视频菜单样式
    var isMenuFloat = true


    //快捷页面标题
    var fastTitle
        get() = CacheMMKV.decodeStringSave("fastTitle", AppContext.getDescById(R.string.app_name))
        set(value) = CacheMMKV.encodeSave("fastTitle", value)

    //码流类型
    var streamType = "1"
        set(value) {
            CacheMMKV.encodeSave("streamType", value)
            field = value
        }

    //是否显示车名
    var isPlate: Boolean = true

    init {
        streamType = CacheMMKV.decodeStringSave("streamType", "1")
        isCenter = CacheMMKV.decodeBooleanSave("isCenter", false)
        isVoice = CacheMMKV.decodeBooleanSave("isVoice", true)
        isMenuFloat = CacheMMKV.decodeBooleanSave("isMenuFloat", true)
    }

    fun init() {
        isMapInfoOpen =
            if (UserConstant.loginType == "car") CacheMMKV.decodeBooleanSave("isMapCarOpen", true)
            else CacheMMKV.decodeBooleanSave("isMapInfoOpen", true)
        isLineInfoOpen =
            if (UserConstant.loginType == "car") CacheMMKV.decodeBooleanSave("isLineCarOpen", true)
            else CacheMMKV.decodeBooleanSave("isLineInfoOpen", true)
    }

    /**
     * 设置上下线
     *
     * @param isOpen
     */
    fun setLineNotice(isOpen: Boolean) {
        this.isOnOffLine = isOpen
        if (UserConstant.loginType == "car") {
            CacheMMKV.encodeSave("isOnOffLineCar", isOpen)
        } else {
            CacheMMKV.encodeSave("isOnOffLine", isOpen)
        }
    }

    /**
     * 设置中心点位置
     *
     * @param isCenter
     */
    fun setMapCenter(isCenter: Boolean) {
        this.isCenter = isCenter
        CacheMMKV.encodeSave("isCenter", isCenter)
    }

    /**
     * 设置报警声音
     *
     * @param isVoice
     */
    fun setAlarmVoice(isVoice: Boolean) {
        this.isVoice = isVoice
        CacheMMKV.encodeSave("isVoice", isVoice)
    }

    /**
     * 设置地图信息弹窗
     *
     * @param isVoice
     */
    fun setMapOpen(isMapInfoOpen: Boolean) {
        this.isMapInfoOpen = isMapInfoOpen
        if (UserConstant.loginType == "car") {
            CacheMMKV.encodeSave("isMapCarOpen", isMapInfoOpen)
        } else {
            CacheMMKV.encodeSave("isMapInfoOpen", isMapInfoOpen)
        }
    }

    fun setLineOpen(isLineOpen: Boolean) {
        this.isLineInfoOpen = isLineOpen
        if (UserConstant.loginType == "car") {
            CacheMMKV.encodeSave("isLineCarOpen", isLineInfoOpen)
        } else {
            CacheMMKV.encodeSave("isLineInfoOpen", isLineInfoOpen)
        }
    }

    fun setEMenuFloat(isMenuFloat: Boolean) {
        this.isMenuFloat = isMenuFloat
        CacheMMKV.encodeSave("isMenuFloat", isMenuFloat)
    }


}

object Constants {
    const val HTTP = "http://"
    const val HTTPS = "https://"

    //使用协议
    var agreeUrl = "https://help.31help.com/privacy/agreement.html"

    //隐私政策 //todo 这需要打包时修改
    var privacyUrl = "https://help.31help.com/privacy/privacyPolicy.html"
//    var privacyUrl = "http://help.31help.com/privacy/privacyPolicy-TX.html"

    //个人信息共享清单
    const val infoShareUrl: String = "https://help.31help.com/privacy/shared.html"

    //个人信息收集清单
    const val infoCollectUrl: String = "https://help.31help.com/privacy/collect.html"


    //使用协议
    const val agreeUrlEN = "https://help.31help.com/privacy/agreementEN.html"

    //隐私政策
    const val privacyUrlEN = "https://help.31help.com/privacy/privacyPolicyEN.html"

    //个人信息共享清单
    const val infoShareUrlEN: String = "https://help.31help.com/privacy/sharedEN.html"

    //个人信息收集清单
    const val infoCollectUrlEN: String = "https://help.31help.com/privacy/collectEN.html"


    //独立安装视频地址
    const val videoInstall = "http://101.133.218.23:9999/video/phone1.mp4"

    //好友安装视频地址
    const val video2Install = "http://101.133.218.23:9999/video/phone2.mp4"

    //自动判断平台连接
    const val marketUrl = "http://bc.31gps.net/wxShare/skip_market_qr.html"

    //上架版更新接口
    fun newVersionUrl() =
        "http://101.133.218.23:9999/api/app/version/getLatest?type=${getVersionType()}"

    //学习课堂
    const val studyUrl = "https://zs.31gps.net:8888/classroom/index.html"

    //获取app版本名称列表
    const val versionListUrl = "https://allgps.31gps.net:8000/api/app/version/getVersionList"

    //获取app版本信息
    const val versionInfoUrl = "https://allgps.31gps.net:8000/api/app/version/getAppVersion"

    //获取app版本类型
    private fun getVersionType(): Int {
        val type = when {
            BuildConfigs.ISGOOGLE -> {
                2
            }

            BuildConfigs.ISCCZS -> {
                5
            }

            else -> {
                1
            }
        }
        return type
    }
}

object MenuKey {
    const val MENU_HOME = "homeSet"
    const val MENU_DATA = "homeData"
    const val MENU_ALL = "homeAll"
    const val MENU_MINE = "homeMe"

    const val MENU_109 = "109"
    const val MENU_101 = "101"
    const val MENU_104 = "104"
    const val MENU_106 = "106"
    const val MENU_107 = "107"
    const val MENU_105 = "105"
    const val MENU_108 = "108"
    const val MENU_905 = "905"
    const val MENU_103 = "103"
    const val MENU_112 = "112"
    const val MENU_fj1 = "fj1"

    const val MENU_fj2 = "fj2"
    const val MENU_fj3 = "fj3"
    const val MENU_fj4 = "fj4"
    const val MENU_102 = "102"
    const val MENU_201 = "201"
    const val MENU_202 = "202"
    const val MENU_203 = "203"
    const val MENU_205 = "205"
    const val MENU_224 = "224"
    const val MENU_208 = "208"

    const val MENU_207 = "207"
    const val MENU_209 = "209"
    const val MENU_210 = "210"
    const val MENU_211 = "211"
    const val MENU_214 = "214"
    const val MENU_204 = "204"
    const val MENU_212 = "212"
    const val MENU_225 = "225"
    const val MENU_909 = "909"
    const val MENU_902 = "902"

    const val MENU_226 = "226"
    const val MENU_227 = "227"
    const val MENU_228 = "228"
    const val MENU_229 = "229"
    const val MENU_230 = "230"
    const val MENU_231 = "231"

    const val MENU_206 = "206"
    const val MENU_217 = "217"
    const val MENU_218 = "218"
    const val MENU_215 = "215"
    const val MENU_216 = "216"
    const val MENU_223 = "223"
    const val MENU_219 = "219"
    const val MENU_222 = "222"
    const val MENU_220 = "220"
    const val MENU_221 = "221"

    const val MENU_213 = "213"
    const val MENU_907 = "907"
    const val MENU_906 = "906"
    const val MENU_908 = "908"
    const val MENU_903 = "903"
    const val MENU_901 = "901"
    const val MENU_can = "can"
    const val MENU_area = "area"
    const val MENU_910 = "910"
    const val MENU_911 = "911"

    const val MENU_110 = "110"
    const val MENU_912 = "912"
    const val MENU_111 = "111"
    const val MENU_913 = "913"
    const val MENU_914 = "914"
    const val MENU_915 = "915"
    const val MENU_916 = "916"
    const val MENU_917 = "917"
    const val MENU_918 = "918"
    const val MENU_919 = "919"


    const val username = "{username}"
    const val password = "{password}"
    const val passwordMd5 = "{password_md5}"
    const val sessionId = "{sessionId}"

    const val MENU_KEY = "menuKey"

}